import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const Agency = [],AuditList=[],DomainList=[]
const count = 100

for (let i = 0; i < count; i++) {
  Agency.push(Mock.mock({
    id:'@increment(1, 100)',
    account: '@first',
    register_time: '@datetime()',
    login_time:  +Mock.Random.date('T'),
    register_ip: Mock.Random.ip(),
    login_ip: Mock.Random.ip(),
    name: '@first',
    nickname: '@first',
    comment: '',
    proxy: '@float(0, 100, 2, 2)',
    level: '@integer(1, 3)',
    balance: '@float(60, 100, 1)',
    money_stream:'@float(60, 100, 1)',
    // 'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': _.map(consts.MEMBER_STATUS, 'value'),
  }))

  AuditList.push(Mock.mock({
    id:'@increment(1, 100)',
    account: '@first',
    time:  +Mock.Random.date('T'),
    applyTime:  +Mock.Random.date('T'),
    auditFirTime:  +Mock.Random.date('T'),
    auditSecTime:  +Mock.Random.date('T'),
    registerIp:Mock.Random.ip(),
    name: '@first',
    auditFirManager: '@first',
    auditSecManager: '@first',
    reason: Mock.Random.ctitle(20),
    auditFirComment: Mock.Random.ctitle(0,20),
    auditSecComment: Mock.Random.ctitle(0,20),
    whoApply: '@first',
    proxy: '@float(0, 100, 2, 2)',
    level: '@integer(1, 3)',
    balance: '@float(60, 100, 1)',
    editContent:'@float(60, 100, 1)',
    'accountType|1': ['CN', 'US', 'JP', 'EU'],
    'editType|1': ['CN', 'US', 'JP', 'EU'],
    'auditFirStatus|1': [0,1,2], //0为待审核，1为审核通过，2为审核不通过
    'auditSecStatus|1': [0,1,2],
  }))

  DomainList.push(Mock.mock({
    id:'@increment(1, 100)',
    account: '@first',
    name: '@first',
    bindTime:  +Mock.Random.date('T'),
    validTime:  +Mock.Random.date('T'),
    model:Mock.Random.ctitle(0,10),
    inviteDomain:'@url',
    independentDomain:Mock.Random.domain('cn'),
    'status|1': _.map(consts.BIND_DOMAIN_STATUS,'value'),
    domains:_.times(3,()=>{ return {value:'qq.com',validTime:+Mock.Random.date('T')}}),
  }))
}

export default {
  [api.AGENCY_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = Agency.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },

  [api.AGENCY_AUDIT_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = AuditList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.AGENCY_DOMAIN_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = DomainList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },

  [api.AGENCY_DOMAIN_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    _.map(DomainList,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
  [api.AGENCY_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    _.map(Agency,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
  [api.AGENCY_AUDIT_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    _.map(AuditList,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
  [api.AGENCY_URLS]: config => {
    const {member_id } = param2Obj(config.body)

    return {
      data: {
        list: [
          'test9.com/?s=11111',
          'test10.com/?s=11111',
          'www.test10.com/',
        ]
      },
      code: 1,
    };
  },
}
